# -*-  coding:utf-8 -*-
# Author : lihongliang

names = [
    ['alex',26,'技术部','工程师',15233654789],
    ['shanshan',25,'公关部','夜魔',15456985478],
    ['longting',23,'设计师','UI',15945632145],
    ['张三', 23, '庄家', 'ee', 123],
    ['李四', 23, '工厂师', 'ee', 3333],
    ['王五', 23,'元师', 'aa', 444],
    ['长剑', 23, '领袖', 'bb', 555],
    ['大刀', 23, '起义', 'ccc', 6666]
]

print(names)
print(names[2][0])
# 查找速度很慢
for i in names:
    if i[0]=='longting':
        print(i)

'''
特性：
key-value结构
key必须hash，且必须为不可变数据类型，必须唯一
可存放任意多个值，可修改，可不唯一
无序
查找速度快
'''
print(" 创建 ".center(50,"="))
dict_name  = {
    "longting":  [23,'设计师','UI',15945632145],
    '张三':[ 15, '庄家', 'ee'],
    '李四': [68, '工厂师', 'ee'],
    '王五': [34,'元师', 'aa'],
    '长剑': [23, '领袖', 'bb'],
    '大刀':[ 73, '起义', 'ccc'],
    '神刀': [66, '起义', 'ccc'],
    '过渡': [24, '起义', 'ccc'],
    '千代': [13, '起义', 'ccc']
}

print(dict_name)

print("  增加  ".center(50,"＊"))
dict_name["武功秘籍一"]="天下第一"
print(dict_name)

print("  修改  ".center(50,"＊"))
dict_name["武功秘籍一"]="葵花宝典"
print(dict_name)
print("=============查找===========")
# 判断是否存在
print("longting" in dict_name)
print("获取数据方式一")
print(dict_name.get("longting"))
print(dict_name.get("longlong")) #不存在的数据，窗口执行 不报错
# 获取数据方式二
print(dict_name["longting"])
# print(dict_name["longlong"])   #不存在的数据，窗口执行 报错
print("================删除==================")
print(dict_name)
print(dict_name.pop('武功秘籍一')) #将指定的数据删除，并将删除的值返回
print(dict_name)
print(dict_name.popitem()) #随机删除
print(dict_name)
del dict_name["longting"]  #指定删除
print(dict_name)


#dict_name.clear()  #清空字典
print(dict_name)
print("=============字典其他用法===========")

print(dict_name.keys())   #取key
print(dict_name.values())  #取值
print(dict_name.items())  #变为列表

print("++++++++++++++++++++++++++++++++++")
print("++++++++++++++++++++++++++++++++++")
info = {
    "alex":'teacher',
    "shanshan":[18,"UI"],
    "jack":[55,"ali"]
}
dic2 = {
    "a":"aaa",
    "b":"bbb",
    "jack":"jack ma  alibaba"
}
info.update(dic2)
print(info)
print("如果存在就返回对应值，如果不存在就增加")
info.setdefault('alex','alex--abc')
print(info)
print("++++++++")
print(info.setdefault('alex','alex--abc'))
print("++++++++")
info.setdefault('abc','abcqqqqqq')
print(info)
print(" fromkeys ".center(50,"*"))
info2 = {}
infoa =info2.fromkeys(['a','b','c'])
print(infoa)
infoa =info2.fromkeys(['a','b','c'],'alex')
print(infoa)
print("=============字典的高效率循环===========")

for k in info:
    print(k,info[k])
print("=============字典的低效率循环===先把字典转化成列表，大数据时不要用========")
for k,v in info.items():
    print(k,v)
print("--------------------123123123--")
for i in info:
    print(i)